﻿@{
    ViewBag.Title = "采样数据分析";
}

@using YmtRpc.Domain;
@using Webdiyer.WebControls.Mvc;
@model PagedList<ServiceDependencySampling>



<script src="~/Content/DatePicker/WdatePicker.js"></script>


<form role="form">
    <div class="form-group">

        <label for="name">角色：</label>
        <select class="form-control" id="dependencyRole" name="dependencyRole" style="width:200px" onchange="UpdateAppIdList()">
            <option value="0">全部</option>
            <option value="1">服务消费者</option>
            <option value="2">服务提供者</option>
        </select>

        <label for="name" style="margin-left:50px">服务名称：</label>
        <select class="form-control" style="width:200px" id="appid" name="appid">
            <option value="">全部</option>
        </select>

        <label for="name" style="margin-left:50px">开始时间：</label>
        <input type="text" class="DateInput form-control" id="BeginTime" style="width:160px" value="@ViewBag.BeginTime" onclick="new WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss', readOnly: true})">
        <label for="name" style="margin-left:50px">结束时间：</label>
        <input type="text" class="DateInput form-control" id="EndTime" style="width:160px" value="@ViewBag.EndTime" onclick="new WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss', readOnly: true, minDate: '#F{$dp.$D(\'BeginTime\')}' })">
        
        <button type="button" class="btn btn-default" onclick="query(); return false;" style="margin-left:10px">查询</button>
    </div>
</form>

<div class="form-group">
    <div id="samplingDataDiv">

        @Html.Partial("_SamplingList", Model)
        @{Html.RegisterMvcPagerScriptResource();}
    </div>
</div>

<script type="text/javascript">

    function UpdateAppIdList() {
        $("#appid").empty();
        $("#appid").append("<option value=\"\">全部</option>");
        $.ajax({
            url: "/Home/GetAppIdListByDependencyRelation?dependencyRelation=" + $("#dependencyRole")[0].value, success: function (data) {
                $.each(data, function (n, e) {
                    $("#appid").append("<option value=\"" + e + "\">" + e + "</option>");
                });
            }
        });
    }

    function query() {
        var url = location.href;
        var href = "/SamplingData/Index?";
        var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");        

        var paraObj = { "dependencyRole": $("#dependencyRole")[0].value, "appid": $("#appid")[0].value, "beginTime": $("#BeginTime")[0].value, "endTime": $("#EndTime")[0].value };
        for (i = 0; j = paraString[i]; i++)
        {
            var key = j.substring(0, j.indexOf("="));

            if (key.length == 0)
                continue;

            if (paraObj[key] == undefined)
                paraObj[key] = j.substring(j.indexOf("=") + 1, j.length);
        }

        var paramStr = '';
        for (var i in paraObj)
        {
            paramStr += i + '=' + paraObj[i] + '&';
        }

        var returnValue = href + paramStr.substring(0, paramStr.length - 1);

        location.href = returnValue;

        return false;
    }

    function goToPage() {
        var pager = Webdiyer.MvcPagers[0];
        if (pager != null) {

            pager.goToPage($("#pagebox").val());

        } else { alert("Can not find the specified MvcPager！"); }

        return false;
    }

    $(document).ready(function () {

        UpdateAppIdList();
    });

</script>